import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import * as path from 'node:path'

export default defineConfig({
	plugins: [vue()],
	resolve: {
		alias: {
			'@': path.resolve(__dirname, 'src')
		}
	},
	server: {
		port: 9000,
		proxy: {
			'/api': {
				target: process.env.VITE_BACKEND_API_URL || 'http://localhost:10000',
				changeOrigin: true,
				rewrite: path => path.replace(/^\/api/, ''),
				secure: false, // 如果是HTTPS目标，设为true；如果是HTTP，保持false
				logLevel: 'debug' // 可选：用于调试代理问题
			}
		}
	},
	define: {
		'process.env': {
			VITE_API_URL: process.env.VITE_API_URL,
			VITE_BACKEND_API_URL: process.env.VITE_BACKEND_API_URL
		}
	}
})
